package org.seanye.erp.view.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.seanye.erp.view.model.Store;
import org.seanye.erp.view.model.WeekStore;

public abstract class AbstractAction extends Action {
    private Store store;
    private TableViewer viewer;

    public Store getStore() {
	return store;
    }

    public void setStore(Store store) {
	this.store = store;
    }

    public AbstractAction(TableViewer viewer, Store store) {
	super();
	this.store = store;
	this.viewer = viewer;
	if (this.store == null && viewer.getInput() instanceof Store) {
	    this.store = (Store) viewer.getInput();
	}
    }

    @Override
    public void run() {
	runInViewer();
	viewer.refresh();
    }

    protected abstract void runInViewer();

    public WeekStore getCurrentStore() {
	IStructuredSelection selection = (IStructuredSelection) viewer
		.getSelection();
	return (WeekStore) selection.getFirstElement();
    }
}
